package com.xz.knowledgeDuplication.thread.state;

/**
 * 线程礼让
 * 让当前正在执行的线程暂停,但不阻塞
 * 将线程从运行态转为就绪态
 * 让cpu重新调度,不一定礼让成功!
 * @author 召
 * @date 2022-07-20 21:21:01
 */
public class Yield implements Runnable{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + " start");
        Thread.yield();
        System.out.println(Thread.currentThread().getName() + " end");
    }

    public static void main(String[] args) {
        Thread thread1 = new Thread(new Yield(), "线程一");
        Thread thread2 = new Thread(new Yield(), "线程二");
        thread1.start();
        thread2.start();
    }
}
